package com.zang.im.croom.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.zang.im.croom.model.dto.WSMessage;
import com.zang.im.croom.util.RedisC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author Zhang Qiang
 * @Date 2019/7/27 16:22
 */
@Service
public class WsMessageServiceImpl implements WsMessageService{

    @Value("${spring.profiles.active}")
    private String serviceName;

    @Autowired
    RedisC redisC;

    @Override
    public WSMessage getWsMeg(Long msgId) {
        return (WSMessage) redisC.get(userKey(msgId));
    }

    @Override
    public void setWsMsg(WSMessage msg) {
        redisC.set(userKey(msg.getMsgId()), msg);
    }

    @Override
    public void delWsMsg(Long msgId) {
        redisC.del(userKey(msgId));
    }

    private String userKey(Long msgId){
        return "msg_"+msgId;
    }

    @Override
    public String test() {
        return "ServiceName: " + serviceName;
    }
}
